package app.biz.config;

import app.biz.service.legacy.LBService;
import app.biz.service.legacy.LBServiceSimpleImpl;
import app.framework.component.HttpClienter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * 基础配置：放置一些common bean
 * 不知为何不能再启用Hystrix方法的类中初始化，否则会报空指针异常！
 * Created by gu on 2017/2/18.
 */
@Configuration
public class CommonConfig {

    private static final Logger logger = LoggerFactory.getLogger(CommonConfig.class);

    @Bean
    @LoadBalanced
    RestTemplate restTemplate(){
        return HttpClienter.getRestTemplate();
    }

    @Value("${ecg.ribbon.listOfServers}")
    private String[] ecgaiUrl;

    @ConditionalOnMissingBean
    @Bean
    LBService lbService(){
        LBService lbService = new LBServiceSimpleImpl();
        lbService.load(ecgaiUrl);
        return lbService;
    }
}
